Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace model.QRecord with []qvalue.QValue #1142

Merged
merged 1 commit into from
Jan 24, 2024
Merged

Replace model.QRecord with []qvalue.QValue #1142

merged 1 commit into from
Jan 24, 2024

Conversation

serprex
Copy link
Contributor

@serprex serprex commented Jan 24, 2024

No description provided.

Also remove NumRecords from QRecordBatch; use `len(batch.Records)`
@@ -130,7 +130,7 @@ func (qe *QRepQueryExecutor) ProcessRows(
fieldDescriptions []pgconn.FieldDescription,
) (*model.QRecordBatch, error) {
// Initialize the record slice
records := make([]model.QRecord, 0)
records := make([][]qvalue.QValue, 0)
Copy link
Contributor

@heavycrystal heavycrystal Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will help readability if we do something like this

type QValueArr []qvalue.QValue

Copy link
Contributor Author

@serprex serprex Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, moving [] to the end as Arr adds little & requires wrapping the type while passing it around, when we just want []qvalue.QValue anyways

I did consider putting type QRecord []qvalue.QValue in model, but seems like it obfuscates the truth. I'm generally annoyed when I'm using a library & it turns out they've wrapped []T into some other type. I'd go as far as to say I'd prefer a type QRecord struct { Values []qvalue.QValue } over a type alias when it comes to wrapping slice types

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it's that double slices read weird, and having an alias for that would help. Fair point on requiring type wrapping though, would a type alias work better? https://stackoverflow.com/questions/61247864/what-is-the-difference-between-type-alias-and-type-definition-in-go

Approving anyway as this is primarily a stylistic difference.

Copy link
Contributor Author

@serprex serprex Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type alias is type wrapping, it's specifically what I want to avoid since it makes a type that you can use slice operators on without being an explicit slice type, so you'll end up casting it to slice when you want to do other things like call functions from slices on it

Double slice is indeed awkward, but it let's someone know they should get used to dealing with nested slices since signature or not that's what they're dealing with

@serprex serprex merged commit 8e08a74 into main Jan 24, 2024
7 checks passed
@serprex serprex deleted the remove-qrecord branch January 24, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants